package com.epay;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

public class Constants
{
  public static String workpath;
  public static String searchModel_package;
  public static String business_package;
  public static String business_service_package;
  public static String dao_package;
  public static String struts_action_pack;
  public static String struts_dto_pack;

  public static String fileName;
  
  public static String dbURL;
  public static String dbUser;
  public static String dbPassword;
  public static String dbDriver;
  public static String tableName;
  public static String dbName;
  public static Map<String,Map<String,String>> objMap=new LinkedHashMap<String,Map<String,String>>();



  public static void init()
  {
    try
    {
      workpath = readParemeter("workpath");
      searchModel_package = readParemeter("searchBean_package");
      business_package = readParemeter("business_package");
      business_service_package = readParemeter("business_service_package");
      dao_package = readParemeter("dao_package");
      struts_action_pack = readParemeter("struts_action_pack");
      struts_dto_pack = readParemeter("struts_dto_pack");
      dbURL = readParemeter("db_url");
      dbUser = readParemeter("db_user");
      dbPassword = readParemeter("db_password");
      dbDriver = readParemeter("db_driver");
      tableName=readParemeter("table_name");
      dbName=readParemeter("db_name");
      fileName=readParemeter("file_name");
      fileName=(fileName==null||"".equals(fileName))?tableCapitalAsLowerCase(tableName):fileName;
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

  public static String readParemeter(String para_name)
    throws Exception
  {
    String record = null;
    int recCount = 0;
    File file = new File(System.getProperty("user.dir")+"", "/src/CodeCreater.cfg");
    FileReader fr = new FileReader(file);
    BufferedReader br = new BufferedReader(fr);
    record = new String();
    while ((record = br.readLine()) != null) {
      recCount++;
      if (record.trim().startsWith(para_name)) {
    	  System.out.println(record);
        /*if (record.indexOf("//") > 0) {
          return record.substring(record.indexOf("=") + 1, record.indexOf("//")).trim();
        }*/
        return record.substring(record.indexOf("=") + 1).trim();
      }
    }

    return "";
  }

  /**
   * 下划线替换成下划线后首字母大写（第一个下划线去掉）
   * @param args
   * @return
   */
  public static String tableCapitalAsLowerCase(String args) {
    StringBuffer buffer=new StringBuffer();
    //变成小写
    args=args.toLowerCase();
//		args=args.substring(2);
    String[] str=args.split("_");
    for (int i=1;i<str.length;i++) {
      String newstr=str[i];
      String newstr1="";
      if(i>1){
        newstr=str[i].substring(0,1).toUpperCase();
        newstr1=str[i].substring(1);
      }

      buffer.append(newstr);
      buffer.append(newstr1);
//			int i=args.indexOf("_");
//			if(i!=-1){
//				String newstr=args.substring(i+1,i+2).toUpperCase();
//				String newstr2=args.substring(i, i+2);
//				args=args.replace(newstr2, newstr);
//			}
    }
    return buffer.toString();
  }
  public static String getSysDate(){
    String dateStr = new SimpleDateFormat("yyyy/MM/dd").format(new Date());
    return dateStr;
  }
  public static void main(String[] args)
    throws Exception
  {
  }
}
